#!/usr/bin/python
# -*- coding: UTF-8 -*-
from django.core.exceptions import ValidationError, NON_FIELD_ERRORS
from django.shortcuts import HttpResponse, render
from django.contrib.auth.models import User
from django.contrib import auth


def checkuser(request):
    if request.method == "GET":
        return render(request, "app_demo/checkuser.html")
    else:
        username = request.POST.get("username")
        pwd = request.POST.get("pwd")
        valid_num = request.POST.get("valid_num")
        keep_str = '123654'
        if valid_num == keep_str:
            user_obj = auth.authenticate(username=username, password=pwd)
            print(user_obj.username)
            if user_obj != None:
                return HttpResponse(user_obj)
            else:
                User.objects.create_user(username=username, password=pwd)
                return HttpResponse('用户不存在,即将创建该用户')
        else:
            print(username)
            print(pwd)
            return HttpResponse("验证码输入错误")
            # return render(request, "app_demo/checkuser.html")
